/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.lct.eq2.socket;

import com.lct.eq2.gui.LiteGui;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Me
 */
public class SocketServer extends Thread {
    LiteGui parent;
    private boolean open;
    Socket socket;
    ServerSocket server;
    
    public SocketServer(LiteGui parent) {
        try {
            this.parent = parent;
            this.open = true;
            this.server = new ServerSocket(13268, 5);
        } catch (IOException ex) {
            Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public SocketServer(Socket sock) {
        //System.out.println("SocketServer::socket port = " + sock.getPort());
        this.open = true;
        this.socket = sock;
    }
    
    public void closeSocket() {
        this.open = false;
    }
    
    @Override
    public void run() {
        while (this.open) {
            try {
                ServerSocketThread thread = new ServerSocketThread(server.accept(), this);
                thread.start();
                //System.out.println(System.currentTimeMillis() + " :: Accepted connection :");
            } catch (IOException ex) {
                Logger.getLogger(SocketServer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
